#include "cv.h"
#include "highgui.h"
#include <stdio.h>

int main(int argc,char** argv){
	IplImage* in=cvLoadImage(argv[1],CV_LOAD_IMAGE_COLOR);
	in->dataOrder=0;//BGR BGR BGR...

	int x,y;
	for(y=0;y<in->height;y++){
		unsigned char* ptr=(unsigned char*)(
				in->imageData+ y*in->widthStep);
		for(x=0; x<in->width;x++){
			if(ptr[3*x+2]<=atoi(argv[2]))
				ptr[3*x]=ptr[3*x+1]=ptr[3*x+2]=0;
			else
				ptr[3*x]=ptr[3*x+1]=ptr[3*x+2]=255;
		}
	}

	cvSaveImage("no_red_out.jpg",in,0);
	cvReleaseImage(&in);
	return 0;
}
